

//
//  ZTAnimationIndicator.m
//  ZTTaxSecond
//
//  Created by Zhengtong on 15/12/7.
//  Copyright © 2015年 Zhengtong. All rights reserved.
//

#import "ZTAnimationIndicator.h"

@implementation ZTAnimationIndicator

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _isAnimating = NO;
        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, frame.size.width,frame.size.height-10)];
        [self addSubview:imageView];
        //设置动画帧
        imageView.animationImages=[NSArray arrayWithObjects:
                                   [UIImage imageNamed:@"load01"],
                                   [UIImage imageNamed:@"load02"],
                                   [UIImage imageNamed:@"load03"],
                                   [UIImage imageNamed:@"load04"],
                                   nil ];

        
        Infolabel = [[UILabel alloc]initWithFrame:CGRectMake(0, frame.size.height-10, frame.size.width, 20)];
        Infolabel.backgroundColor = [UIColor clearColor];
        Infolabel.textAlignment = NSTextAlignmentCenter;
        Infolabel.textColor = [UIColor lightGrayColor];
        Infolabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:Infolabel];
        self.layer.hidden = YES;
    }
    return self;
}


- (void)startAnimation
{
    _isAnimating = YES;
    self.layer.hidden = NO;
    [self doAnimation];
}
-(void)doAnimation{
    Infolabel.text = _loadtext;
    //设置动画总时间
    imageView.animationDuration=0.4;
    //设置重复次数,0表示不重复
    imageView.animationRepeatCount=0;
    //开始动画
    [imageView startAnimating];
}

- (void)stopAnimationWithLoadText:(NSString *)text withType:(BOOL)type;
{
    _isAnimating = NO;
    Infolabel.text = text;
    if(type){
        [imageView stopAnimating];
        self.layer.hidden = YES;
        self.alpha = 1;


    }else{
        [imageView stopAnimating];
        [imageView setImage:[UIImage imageNamed:@"3"]];
    }
    
}


-(void)setLoadText:(NSString *)text;
{
    if(text){
        _loadtext = text;
    }
}

@end
